package logic

import (
	"context"
	"tiktok/rpc/pb"

	"tiktok/api/internal/svc"
	"tiktok/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddLogic) Add(req *types.TiktokAddRequest) (resp *types.ApiResponse, err error) {
	// todo: add your logic here and delete this line
	tiktok, err := l.svcCtx.TiktokSrv.Tiktok(l.ctx, &pb.TiktokAddReq{
		Name:   req.Name,
		Phone:  req.Phone,
		Source: req.Source,
		Code:   req.Code,
	})
	if err != nil {
		return &types.ApiResponse{
			Code: -1,
			Msg:  "注册失败",
			Data: nil,
		}, nil
	}
	return &types.ApiResponse{
		Code: 200,
		Msg:  "注册成功",
		Data: tiktok,
	}, nil
}
